import { BaseApi, ClientOptions } from "./flora-api-base";
import { DataAPI } from "./flora-api-dash/data-api";
import { GQLClient, GQLLoader } from "./utils/gql";

export function createDashApi(opts: { clientOptions: ClientOptions, base: BaseApi }) {
  const gqlClient = createGQLClient(opts);
  return {
    dataApi: new DataAPI(gqlClient),
  }
}

function createGQLClient(opts: { clientOptions: ClientOptions, base: BaseApi }): GQLClient {
  const c = {
    request: opts.base.request,
    isServer: opts.base.isServer,
    isDev: opts.base.isDev,
    endpointPath: '/gql/endpoint',
    batchedEndPointPath: '/gql/endpoint_batch',
    gqlLoader: undefined as any,
  };
  c.gqlLoader = new GQLLoader(c);
  return c;
}
